<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use App\Http\Resources\CommissionResource;
use App\Models\Commission;
use App\Models\Order;
use App\Models\SUsers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class CommissionController extends Controller
{
    /**
     * 获取佣金列表
     * @param Request $request
     * @return array
     */
    public function getCommissions(Request $request){
        $validator = Validator::make($request->all(), [
            'openid' => "required",
        ]);
        if ($validator->fails()) {
            return [
                "result" => "failed",
                "message" => $validator->errors()
            ];
        }
        $user = getUser($request);
        $commissions = Commission::where('user_id',$user->id)->paginate(10);
        return[
            'result'=>'success',
            'data'=>[
                'commission_amount'=>$user['commission'],
                'commission_record'=>CommissionResource::collection($commissions),
            ],
            'last_page' => $commissions->lastPage()
        ];

    }

    public function test(Request $request){



    }


}
